package openbang.account.service.util;

import java.util.logging.Logger;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import openbang.account.service.vo.CacheKeyDefine;

/**
 * Session的监听器
 * 
 * 目的：
 * 
 * 
 * 对 Servlet容器的版本的要求 2.3以上
 * 
 *  web.xml要增加：
 * <listener>
      <listener-class>openbang.account.service.util.WebSessionLifeListener</listener-class>
   </listener>
   <session-config>
      <session-timeout>10</session-timeout>
   </session-config>
 * 
 * @author aibo zeng
 *
 */

public class WebSessionLifeListener implements HttpSessionListener,ServletContextListener {
	private static final Logger log = Logger.getLogger(WebSessionLifeListener.class.getName());
	public void sessionCreated(HttpSessionEvent arg0) {
	}

	public void sessionDestroyed(HttpSessionEvent arg0) {
		CacheHelper.removeOnly(CacheKeyDefine.SESSION_PREFIX + arg0.getSession().getId());
		log.warning("sessionDestroyed remove cache.");
	}

	public void contextDestroyed(ServletContextEvent arg0) {
		//系统退出时
	}

	public void contextInitialized(ServletContextEvent arg0) {
		//系统启动后
	}
}
